package com.example.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    public final static String es_queue = "es_queue";
    public final static String es_exchage = "es_exchage";
    public final static String es_bind_key = "es_exchage";

    @Bean //新建一个队列
    public Queue exQueue() {
        return new Queue(es_queue);
    }

    @Bean //新建一个交换机
    DirectExchange exchange() {
        return new DirectExchange(es_exchage);
    }

    @Bean //队列和交换机进行绑定
    //当我发送一条消息发送到交换机的时候，并且指定了bingkey，就会把消息保存到queue里面，然后消费者监听到消息在这个队列时候就能
    //消费到对应消息了
    Binding binding(Queue exQueue, DirectExchange exchange) {
        return BindingBuilder.bind(exQueue).to(exchange).with(es_bind_key);
    }

}
